<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>在旧 IE 中添加和删除多个事件监听器</title>
</head>
<body>
<img id="img-0" src="usa.gif" alt="usa">
<div id="status"></div>
<script>
    var myImages = [
        'usa.gif',
        'canada.gif',
        'jamaica.gif',
        'mexico.gif'
    ];

    function changeImg(e) {
        var newImgNumber;
        do {
            newImgNumber = Math.round(Math.random() * 3);
        } while (e.srcElement.src.indexOf(myImages[newImgNumber]) != -1);
        e.srcElement.src = myImages[newImgNumber];
        e.srcElement.alt = myImages[newImgNumber];
    }

    function updateStatus(e) {
        var status = document.getElementById('status');
        status.innerHTML = 'The iamge changed to ' + e.srcElement.src;
        if (e.srcElement.indexOf('mexico') != -1) {
            e.srcElement.removeEventListener('onclick', changeImg);
            e.srcElement.removeEventListener('onclick', updateStatus);
        }
    }

    var imgObj = document.getElementById('img-0');
    imgObj.attachEvent('onclick', updateStatus);
    imgObj.attachEvent('onclick', changeImg);
</script>
</body>
</html>